package com.cheetah.start.system.mail.controller;

import com.cheetah.start.common.annotation.ApiCount;
import com.cheetah.start.common.base.result.Result;
import com.cheetah.start.common.base.result.ResultController;
import com.cheetah.start.system.mail.domain.MailDo;
import com.cheetah.start.system.mail.service.MailService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.mail.MessagingException;

/**
 * 邮件
 *
 * @author Feel
 * @date 2021/08/19
 */
@Api(tags = "邮件发送")
@Slf4j
@ApiCount
@Validated
@CrossOrigin
@RestController
@RequestMapping("/mail")
public class MailController extends ResultController {

    @Autowired
    private MailService mailService;

    /**
     * 发送邮件 可发送 html 内容
     *
     * @param mailDo 邮件
     * @return {@link Result}
     * @throws MessagingException 邮件异常
     */
    @PostMapping("/send")
    public Result send(MailDo mailDo) throws MessagingException {
        mailService.sendMail(mailDo);
        return success("邮件已发送");
    }


}
